package IC.Parser;      

//LexicalError Class
public class LexicalError extends Exception  {             
	         
	private static final long serialVersionUID = 1L;
	private int line = -1;          
	private String value = null;         
	private ErrorType errorType = null;           
	
	//C'tor
	public LexicalError(String message) {                  
		super(message);      
	}                
	
	//C'tor
	public LexicalError(int line, ErrorType errorType, String value) { 
		this.line = line;                                   
		this.errorType = errorType;                  
		this.value = value;          
	}            
	
	//C'tor
	public LexicalError(int line, ErrorType errorType) {          
		this(line, errorType, null);         
	}             
	
	//getMessage
	public String getMessage() {          
		if (line==-1)                 
			return super.getMessage();  
		
		String msg=this.line + ": Lexical error: "+ errorType.toString();
		
		if (this.value!=null)
			msg+= " '"+ this.value + "'";     
		
		return msg;
	}            
	  
	public enum ErrorType {          
		INVALID_ID("illegal ID"), 				              
		INVALID_INTEGER("illegal integer"), 	         
		INVALID_NUMBER("illegal number"), 		         
		INVALID_CHAR("illegal character"),
		INVALID_COMMENT("illegal comment"),
		INVALID_STRING("String literal is not properly closed by a double-quote");
		
		private final String Msg;                    
		
		//Enum C'tor 
		ErrorType(String Msg) {                          
			this.Msg = Msg;                 
			}                    
		
		//toString
		public String toString() {                          
			return Msg;                       
			}      
		}  
}  
	


